using Microsoft.AspNetCore.Mvc;
using SportsPlatform.Base;
using SportsPlatform.Dto.WeChat;
using SportsPlatform.Query.WeChat;
using SportsPlatform.Dto.SportBusiness.Category;
using SportsPlatform.Dto.SportBusiness.Information;
using SportsPlatform.Query.WeChat;
using SportsPlatform.WeChat.IWeChat;
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;

namespace SportsPlatform.Controllers
{
    /// <summary>
    /// 移动端首页控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [AllowAnonymousAttribute]
    public class WeChatIndexController : SportsPlatformControllerBase
    {
        #region 私有变量

        private IIndexService _indexService;
        private INewsService _newsService;
        private ICategoryService _categoryService;

        #endregion

        #region 构造函数

        public WeChatIndexController(IIndexService index, ICategoryService categoryService, INewsService newsService)
        {
            _indexService = index;
            _newsService = newsService;
            _categoryService = categoryService;
        }

        #endregion


        #region 公共API接口

        /// <summary>
        ///  赛事列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagePagingDto<GetHotCompetitionListDto>> GetHotCompetitionList([FromBody] GetHotCompetitionListQuery query)
        {
            return await _indexService.GetHotCompetitionList(query);
        }


        /// <summary>
        ///  首页获取热门赛事列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultListDto<GetHotCompetitionListDto>> GetHotCompetitionList()
        {
            return await _indexService.GetHotCompetitionList();
        }

        /// <summary>
        /// 获取赛事详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<GetIndexCompetitionDetailsDto>> GetCompetitionDetails([FromBody] GetCompetitionDetailsQuery query)
        {
            return await _indexService.GetCompetitionDetails(query);
        }

        /// <summary>
        /// 获取赛事比赛项目
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<GetCompetitionProjectListDto>> GetCompetitionProjectList([FromBody] GetCompetitionProjectListQuery query)
        {
            return await _indexService.GetCompetitionProjectList(query);
        }

        /// <summary>
        /// 通过查询条件获取分页后的赛事列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagePagingDto<GetHotCompetitionListDto>> GetCompetitionList([FromBody] GetCompetitionListQuery query)
        {
            return await _indexService.GetCompetitionList(query);
        }

        /// <summary>
        /// 根据年份获取赛事名称
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<GetYearCompetitionNameDto>> GetYearCompetitionName([FromBody] GetYearCompetitionNameQuery query)
        {
            return await _indexService.GetYearCompetitionName(query);
        }

        /// <summary>
        /// 获取赛事项目名称集合
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<GetCompetitionProjectNameDto>> GetCompetitionProjectName([FromBody] GetCompetitionProjectNameQuery query)
        {
            return await _indexService.GetCompetitionProjectName(query);
        }

        /// <summary>
        /// 获取成绩信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<GetAchievementInfoDto>> GetAchievementInfo([FromBody] GetAchievementInfoQuery query)
        {
            return await _indexService.GetAchievementInfo(query);
        }

        /// <summary>
        /// 获取历史成绩信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<GetHistoryAchievementInfoDto>> GetHistoryAchievementInfo([FromBody] GetHistoryAchievementInfoQuery query)
        {
            return await _indexService.GetHistoryAchievementInfo(query);
        }


        #region Information

        /// <summary>
        /// 通过分类标识获取相关资讯信息
        /// </summary>
        /// <param name="query">传入参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<GetByCategoryIdToNewsDto>> GetByCategoryIdToNews([FromBody] WeChatGetCategoryQuery query)
        {
            return await _newsService.GetByCategoryIdToNews(query);
        }

        /// <summary>
        /// 通过标识获取对应的资讯信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultDto<GetInformationByIdDto>> GetInformationById([FromBody] GetInformationByIdQuery query)
        {
            return await _newsService.GetInformationById(query);
        }

        /// <summary>
        /// 获取所有资讯
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<PagePagingDto<GetByCategoryIdToNewsDto>> GetInformationList([FromBody] BasePageQuery query)
        {
            return await _newsService.GetInformationList(query);
        }


        #endregion


        #region Category

        /// <summary>
        /// 获取所有资讯分类信息列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultListDto<GetListCategoryDto>> GetListCategory()
        {
            return await _categoryService.GetCategoryList();
        }

        #endregion

        #endregion
    }
}
